package com.gitee.huanminabc.dynamicdb.aop.transa;

import com.gitee.huanminabc.dynamicdb.core.DBSwatchUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
/**
 * @author huanmin
 * @date 2024/11/22
 */
@Aspect
@Component
@Slf4j
@Order(Integer.MIN_VALUE+10)
public class DBTransactionalAspect {

    @Pointcut("@annotation(com.gitee.huanminabc.dynamicdb.aop.DBTransactional)")
    public void DBTransactional() {
    }

    @Around("DBTransactional()")
    public Object dBTransactionalAnno(ProceedingJoinPoint thisJoinPoint) throws Throwable {
        //给指定的数据源开启事务
        return  DBSwatchUtil.muchTransactional(thisJoinPoint::proceed);
    }


}
